﻿@{
    ViewBag.Title = "DBAudit";
    Layout = "~/Views/Shared/_Layout_Administration.cshtml";
}

<div id="main">
    <div class="preloader preloader"></div>
    <div class="preloader-replacement hide">
        <table class="table-striped">
            <thead>
                <tr>
                    <th>Id
                    </th>
                    <th>Entity
                    </th>
                    <th>EntityId
                    </th>
                    <th>State
                    </th>
                    <th>Property
                    </th>
                    <th>OldValue
                    </th>
                    <th>NewValue
                    </th>
                    <th>Author
                    </th>
                    <th>CreationDate
                    </th>
                </tr>
            </thead>
            <tbody data-bind="foreach: DBChangesAudit">
                <tr>
                    <td data-bind="text: Id"></td>
                    <td data-bind="text: Entity"></td>
                    <td data-bind="text: EntityId"></td>
                    <td data-bind="text: State"></td>
                    <td data-bind="text: Property"></td>
                    <td data-bind="text: OldValue"></td>
                    <td data-bind="text: NewValue"></td>
                    <td data-bind="text: Author"></td>
                    <td data-bind="text: CreationDate"></td>
                </tr>
            </tbody>
        </table>

    </div>

</div>

@section scripts{

    <script type="text/javascript">

        function DBChangesAudit(data) {
            this.Id = ko.observable(data.Id);
            this.Entity = ko.observable(data.Entity);
            this.EntityId = ko.observable(data.EntityId);
            this.State = ko.observable(data.State);
            this.Property = ko.observable(data.Property);
            this.OldValue = ko.observable(data.OldValue);
            this.NewValue = ko.observable(data.NewValue);
            this.Author = ko.observable(data.Author);
            this.CreationDate = ko.observable(data.CreationDate);
        }

        var self;


        function PageGroupListViewModel() {
            self = this;
            self.DBChangesAudit = ko.observableArray([]);

            self.loadDataFromServer = function () {
                $.getJSON("GetDBChangesAudit", function (allData) {
                    var mappedDBChangesAudit = $.map(allData, function (item) { return new DBChangesAudit(item) });
                    self.DBChangesAudit(mappedDBChangesAudit);

                    TogglePreloader('.preloader', '.preloader-replacement');
                });
            };

            self.loadDataFromServer();

        }

        ko.applyBindings(new PageGroupListViewModel());

    </script>

}